/**
 *   Copyright 2014 Royce Remulla
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package cjcast.y2010.qual;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * TODO:
 * 
 * @author royce.com@gmail.com
 */
public class NameScoreReader {

    List<Player> readFile(final String fileName) throws IOException
    {
        final List<Player> retval = new ArrayList<Player>();

        final Path path = Paths.get(fileName);
        final List<String> source = Files.readAllLines(
            path,
            StandardCharsets.UTF_8);
        for (final String line : source) {
            final String[] array = line.split(":");
            if (array.length == 2) {
                retval.add(new Player(array[0], Integer.parseInt(array[1])));
            } else {
                System.out.println("Invalid format: " + array);
            }
        }
        return retval;
    }


    class Player {

        protected Player(final String pName, final int pScore) {
            super();
            this.name = pName;
            this.score = pScore;
        }

        private String name;

        private int score;

        public String getName()
        {
            return this.name;
        }

        public void setName(final String name)
        {
            this.name = name;
        }

        public int getScore()
        {
            return this.score;
        }

        public void setScore(final int score)
        {
            this.score = score;
        }

    }

}